package com.fyi.controller;

import com.fyi.exception.MyException;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

public class BaseController {

    @ExceptionHandler
    public String exception(HttpServletRequest request, Exception ex){
        request.setAttribute("ex",ex);

        //根据参数中异常对象，调用对应的异常界面
        if(ex instanceof MyException){
            return "exception/my-error";
        }else if (ex instanceof SQLException){
            return "exception/sql-error";
        }
        return "exception/error";
    }
}
